require "UI/Bag/bag_model"
local _BagView = require "UI/Bag/bag_view"
local _BagSmallView = require "UI/Bag/bag_small_view"

BagController = BagController or BaseClass()
local BagController = BagController
local _LuaEMgr = LuaEventManager:GetInstance()

function BagController:__init()
    -- BagController.Instance = self
    self.model = BagModel:GetInstance()
    self:InitEvent()
end

function BagController:GetInstance()
	if BagController.Instance == nil then
		BagController.Instance = BagController.New()
	end
	return BagController.Instance
end

function BagController:InitEvent()
	local function onOpenBagView()
		if self.bag_view == nil then
			self.bag_view = _BagView.New()
		end
		self.bag_view:Open()
	end
	-- self.model:Bind(BagModel.EVENT_NAME.OPEN_BAG_VIEW, onOpenBagView)
	_LuaEMgr:AddListener(EVENT_NAME.OPEN_BAG_VIEW, onOpenBagView)

	local function onOpenBagSmallView()
		if self.bag_small_view == nil then
			self.bag_small_view = _BagSmallView.New()
		end
		self.bag_small_view:Open()
	end
	self.model:Bind(BagModel.EVENT_NAME.OPEN_BAG_SMALL_VIEW, onOpenBagSmallView)
end

return BagController